package com.ruoyi.sbgl.xmxxgl.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sbgl.xmxxgl.domain.Xmxxgl;
import com.ruoyi.sbgl.xmxxgl.service.IXmxxglService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;

/**
 * 项目信息管理Controller
 *
 * @author huacai
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/sbgl/xmxxgl")
public class XmxxglController extends BaseController {
    @Resource
    private IXmxxglService xmxxglService;

    /**
     * 查询项目信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:list')")
    @GetMapping("/list")
    public TableDataInfo list(Xmxxgl xmxxgl) {
        startPage();
        List<Xmxxgl> list = xmxxglService.selectXmxxglList(xmxxgl);
        return getDataTable(list);
    }

    /**
     * 不分页查询项目列表
     * @return
     */
    @GetMapping("/selectXmList")
    public AjaxResult selectXmList() {
        List<Xmxxgl> list = xmxxglService.selectXmList();
        return AjaxResult.success(list);
    }

    /**
     * 导出项目信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:export')")
    @Log(title = "项目信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Xmxxgl xmxxgl) {
        List<Xmxxgl> list = xmxxglService.selectXmxxglList(xmxxgl);
        ExcelUtil<Xmxxgl> util = new ExcelUtil<Xmxxgl>(Xmxxgl.class);
        util.exportExcel(response, list, "项目信息管理数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Xmxxgl> util = new ExcelUtil<Xmxxgl>(Xmxxgl.class);
        util.importTemplateExcel(response, "项目信息管理数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "项目信息管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<Xmxxgl> util = new ExcelUtil<Xmxxgl>(Xmxxgl.class);
        InputStream inputStream = file.getInputStream();
        List<Xmxxgl> list = util.importExcel(inputStream);
        inputStream.close();
        int count = xmxxglService.batchInsertXmxxgl(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取项目信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:query')")
    @GetMapping(value = "/{xmxxglId}")
    public AjaxResult getInfo(@PathVariable("xmxxglId") Integer xmxxglId) {
        return success(xmxxglService.selectXmxxglByXmxxglId(xmxxglId));
    }

    /**
     * 新增项目信息管理
     */
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:add')")
    @Log(title = "项目信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Xmxxgl xmxxgl) {
        return toAjax(xmxxglService.insertXmxxgl(xmxxgl));
    }

    /**
     * 修改项目信息管理
     */
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:edit')")
    @Log(title = "项目信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Xmxxgl xmxxgl) {
        return toAjax(xmxxglService.updateXmxxgl(xmxxgl));
    }

    /**
     * 删除项目信息管理
     */
    @PreAuthorize("@ss.hasPermi('sbgl:xmxxgl:remove')")
    @Log(title = "项目信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{xmxxglIds}")
    public AjaxResult remove(@PathVariable Integer[] xmxxglIds) {
        return toAjax(xmxxglService.deleteXmxxglByXmxxglIds(xmxxglIds));
    }
}
